﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;

namespace EasyTest {

    /// <summary>
    /// Textbox object
    /// </summary>
    public class TextBox : IElement {

        /// <summary>
        /// Create a new TextBox object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        public TextBox(string findBy) {
            FindBy = findBy;
            Focus = new Focus();
        }

        /// <summary>
        /// Create a new TextBox object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        public TextBox(string findBy, Focus focus)
            : this(findBy) {
            Focus = focus;
        }

        /// <summary>
        /// Get the value of the TextBox object.
        /// </summary>
        /// <returns>String representing the Value of the TextBox.</returns>
        public string Value() {
            Focus.Go();
            return Action.GetValue(FindBy);
        }

        /// <summary>
        /// Clear the TextBox.
        /// </summary>
        public void Clear() {
            Focus.Go();
            Action.Clear(FindBy);
        }

        /// <summary>
        /// Set the value of the Textbox to the text passed.
        /// </summary>
        /// <param name="text">Text to set in this TextBox</param>
        public void Set(string text) {
            Focus.Go();
            Action.Clear(FindBy);
            Action.Set(FindBy, text);
        }

        /// <summary>
        /// Verify that the .Text property is set to the expected value passed.
        /// </summary>
        /// <param name="expectedValue">Text to find in the TextBox object.</param>
        public void VerifyValue(string expectedValue) {
            VerifyValue(expectedValue, "");
        }
        /// <summary>
        /// Verify that the .Text property is set to the expected value passed.
        /// </summary>
        /// <param name="expectedValue">Text to find in the TextBox object.</param>
        /// <param name="errorMessage">Error message to be displayed if there is no match.</param>
        public void VerifyValue(string expectedValue, string errorMessage) {
            GoTo();
            Action.Verify.Value(FindBy, expectedValue, Focus, errorMessage);
        }

        /// <summary>
        /// Checks that it is displayed on web page.  
        /// </summary>
        /// <param name="message">There error message to dispaly if does not displayed</param>
        public void VerifyDisplayed(string message) {
            GoTo();
            Action.Verify.IsDisplayed(FindBy, Focus, message);
        }

        /// <summary>
        /// Checks that it is displayed on web page.  
        /// </summary>
        public void VerifyDisplayed() {
            VerifyDisplayed("");
        }

        /// <summary>
        /// Checks whether or not this TextBox Document Element exists.
        /// </summary>
        /// <returns>True/False whether or not the Document Element exists</returns>
        public bool Exist() {
            GoTo();
            return Action.Exist(FindBy);
        }

        /// <summary>
        /// Checks whether or not this TextBox Document Element exists and is displayed (visible).
        /// </summary>
        /// <returns>True/False whether or not the Document Element exists and is displayed (visible).</returns>
        public bool Displayed() {
            GoTo();
            return Action.IsDisplayed(FindBy);
        }

    }

}
